//
//  ERMineVC.m
//  EnjoyRunning
//
//  Created by ljm on 2017/3/15.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "ERMineVC.h"
#import "ERBaseVC.h"

#import "ERMyRunFriendsVC.h"
#import "ERMyRunTeamVC.h"
#import "ERMyEquipmentsVC.h"
#import "ERRunStatisticsVC.h"
#import "ERRunGradeVC.h"

#import "ERMineCell.h"

@interface ERMineVC ()<UITableViewDataSource,UITableViewDelegate>

    @property(nonatomic,strong) UITableView *myTableView;
    
@end

@implementation ERMineVC


#pragma mark -- 设置navigation导航条
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [leftBtn setImage:[UIImage imageNamed:@"mine_normal"] forState:UIControlStateNormal];
    UIBarButtonItem *selfLeftImage = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = selfLeftImage;
    
    //right
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    [rightBtn setImage:[UIImage imageNamed:@"mine_select"] forState:UIControlStateNormal];
    [rightBtn setTintColor:[UIColor whiteColor]];
    UIBarButtonItem *selfRightImage = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = selfRightImage;
    
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
}

#pragma mark -- interface
- (void)setupUI
    {
        [self.view addSubview:self.myTableView];
        
        /*
         *    让视图的背景颜色和主题色保持一致
         */
        self.view.backgroundColor = rootVC.view.backgroundColor;
    }

#pragma mark -- uitableview data source

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 3;
    }
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        if (section == 0) {
            return 1;
        }else
        {
            return 2;
        }
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return  50;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 20;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
        return 0.0000001;
    }
    
  #pragma mark -- cellForRowAtIndexPath
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *identifier = @"myCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
//        }else
//        {
//            //删除cell的所有子视图
//            while ([cell.contentView.subviews lastObject] != nil)
//            {
//                [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];
//            }
//        }
        
//        cell.backgroundColor = [UIColor whiteColor];
        
        /*
         *    小箭头
         */
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        if (indexPath.section == 0) {
//            cell.myIconImage.image = [UIImage imageNamed:@"mine_normal"];
//            cell.myTitleLab.text = @"我的跑友";
            cell.imageView.image = [UIImage imageNamed:@"mine_normal"];
            cell.textLabel.text = @"我的跑友";
            
        }else if (indexPath.section == 1 && indexPath.row == 0)
        {
//            cell.myIconImage.image = [UIImage imageNamed:@"mine_normal"];
//            cell.myTitleLab.text = @"我的跑团";
            cell.imageView.image = [UIImage imageNamed:@"mine_normal"];
            cell.textLabel.text = @"我的跑团";
        }else if (indexPath.section == 1 && indexPath.row == 1)
        {
//            cell.myIconImage.image = [UIImage imageNamed:@"mine_normal"];
//            cell.myTitleLab.text = @"我的装备";
            cell.imageView.image = [UIImage imageNamed:@"mine_normal"];
            cell.textLabel.text = @"我的装备";
        }else if (indexPath.section == 2 && indexPath.row == 0)
        {
//            cell.myIconImage.image = [UIImage imageNamed:@"mine_normal"];
//            cell.myTitleLab.text = @"跑步统计";
            cell.imageView.image = [UIImage imageNamed:@"mine_normal"];
            cell.textLabel.text = @"跑步统计";
        }else
        {
//            cell.myIconImage.image = [UIImage imageNamed:@"mine_normal"];
//            cell.myTitleLab.text = @"跑步等级";
            cell.imageView.image = [UIImage imageNamed:@"mine_normal"];
            cell.textLabel.text = @"跑步等级";
        }
        
        return cell;
    }
    
  #pragma mark -- didSelectRowAtIndexPath
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {

        if (indexPath.section == 0) {
            /*
             *    我的跑友
             */
            ERMyRunFriendsVC *myRunFriendsVC = [[ERMyRunFriendsVC alloc] init];
            myRunFriendsVC.title = @"我的跑友";
            [self.navigationController pushViewController:myRunFriendsVC animated:YES];
            
        }else if (indexPath.section == 1 && indexPath.row == 0)
        {
            /*
             *    我的跑团
             */
            ERMyRunTeamVC *myRunTeamVC = [[ERMyRunTeamVC alloc] init];
            myRunTeamVC.title = @"我的跑团";
            [self.navigationController pushViewController:myRunTeamVC animated:YES];
            
        }else if (indexPath.section == 1 && indexPath.row == 1)
        {
            /*
             *    我的装备
             */
            ERMyEquipmentsVC *myEquipmentsVC = [[ERMyEquipmentsVC alloc] init];
            myEquipmentsVC.title = @"我的装备";
            [self.navigationController pushViewController:myEquipmentsVC animated:YES];
            
        }else if (indexPath.section == 2 && indexPath.row == 0)
        {
            /*
             *    跑步统计
             */
            ERRunStatisticsVC *runStatisticVC = [[ERRunStatisticsVC alloc] init];
            runStatisticVC.title = @"跑步统计";
            [self.navigationController pushViewController:runStatisticVC animated:YES];
            
        }else
        {
            /*
             *    跑步等级
             */
            ERRunGradeVC *runGradeVC = [[ERRunGradeVC alloc] init];
            runGradeVC.title = @"跑步等级";
            [self.navigationController pushViewController:runGradeVC animated:YES];
        }
    }
    
#pragma mark -- getter
- (UITableView *)myTableView
    {
        if (!_myTableView) {
            _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64 , kwidth, kheight) style:UITableViewStyleGrouped];
            _myTableView.backgroundColor = self.view.backgroundColor;
            _myTableView.delegate = self;
            _myTableView.dataSource = self;
            _myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
            _myTableView.alwaysBounceVertical = YES;
        }
        return _myTableView;
    }
@end
